const {resolve} = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  entry: "./src/index.js",
  output: {
    path: resolve(__dirname, "build"),
    filename: "js/bundle.js"
  },
  module: {
    rules: [
      // 打包样式
      {
        test: /\.less$/,
        use: ['style-loader', 'css-loader', 'less-loader']
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      // 打包图片
      {
        test: /\.(jpg|jpeg|png|gif)$/,
        loader: 'url-loader',
        options: {
          limit: 8 * 1024,
          outputPath: 'imgs' // 指定输出目录
        }
      },
      {
        test: /\.html$/,
        loader: 'html-loader', // 处理HTML中的img标签图片
      },
      // 打包其他资源
      {
        exclude: /.(html|js|css|less|jpg|jpeg|png|gif)/,
        loader: 'file-loader',
        options: {
          outputPath: 'media'
        }
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin(
      {
        template: './src/index.html'
      }
    )
  ],
  mode: "development",
  devServer: {
    contentBase: resolve(__dirname, 'build'),
    compress: true,
    port: 9002,
    open: true
  }
}